// Code generated by ent, DO NOT EDIT.

package ent

import (
	"context"
	"server/components/models/ent/predicate"
	"server/components/models/ent/regiontype"

	"entgo.io/ent/dialect/sql"
	"entgo.io/ent/dialect/sql/sqlgraph"
	"entgo.io/ent/schema/field"
)

// RegionTypeDelete is the builder for deleting a RegionType entity.
type RegionTypeDelete struct {
	config
	hooks    []Hook
	mutation *RegionTypeMutation
}

// Where appends a list predicates to the RegionTypeDelete builder.
func (rtd *RegionTypeDelete) Where(ps ...predicate.RegionType) *RegionTypeDelete {
	rtd.mutation.Where(ps...)
	return rtd
}

// Exec executes the deletion query and returns how many vertices were deleted.
func (rtd *RegionTypeDelete) Exec(ctx context.Context) (int, error) {
	return withHooks(ctx, rtd.sqlExec, rtd.mutation, rtd.hooks)
}

// ExecX is like Exec, but panics if an error occurs.
func (rtd *RegionTypeDelete) ExecX(ctx context.Context) int {
	n, err := rtd.Exec(ctx)
	if err != nil {
		panic(err)
	}
	return n
}

func (rtd *RegionTypeDelete) sqlExec(ctx context.Context) (int, error) {
	_spec := sqlgraph.NewDeleteSpec(regiontype.Table, sqlgraph.NewFieldSpec(regiontype.FieldID, field.TypeInt64))
	if ps := rtd.mutation.predicates; len(ps) > 0 {
		_spec.Predicate = func(selector *sql.Selector) {
			for i := range ps {
				ps[i](selector)
			}
		}
	}
	affected, err := sqlgraph.DeleteNodes(ctx, rtd.driver, _spec)
	if err != nil && sqlgraph.IsConstraintError(err) {
		err = &ConstraintError{msg: err.Error(), wrap: err}
	}
	rtd.mutation.done = true
	return affected, err
}

// RegionTypeDeleteOne is the builder for deleting a single RegionType entity.
type RegionTypeDeleteOne struct {
	rtd *RegionTypeDelete
}

// Where appends a list predicates to the RegionTypeDelete builder.
func (rtdo *RegionTypeDeleteOne) Where(ps ...predicate.RegionType) *RegionTypeDeleteOne {
	rtdo.rtd.mutation.Where(ps...)
	return rtdo
}

// Exec executes the deletion query.
func (rtdo *RegionTypeDeleteOne) Exec(ctx context.Context) error {
	n, err := rtdo.rtd.Exec(ctx)
	switch {
	case err != nil:
		return err
	case n == 0:
		return &NotFoundError{regiontype.Label}
	default:
		return nil
	}
}

// ExecX is like Exec, but panics if an error occurs.
func (rtdo *RegionTypeDeleteOne) ExecX(ctx context.Context) {
	if err := rtdo.Exec(ctx); err != nil {
		panic(err)
	}
}
